/* JavaLog - package tracker 
* 
* Copyright (C) 2009 Allyson Lima, Diego Pedro, Victor Freire
* 
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software 
* Foundation, either version 3 of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along with this 
* program. If not, see <http://www.gnu.org/licenses/>.
*/
package br.edu.ufcg.ccc.javalog;

/**
 * Represents a common Franchise.
 * @author Allyson Lima, Diego Pedro, Victor Freire
 * @version 11/10/09
 */
public class Franchise {
	
	private String name;
	private Address address;
	private boolean hasAirport;
	private int packagesHandled=0;
	private int sales=0;
	
	/**
	 * 
	 * @param name of the Franchise
	 * @param address of the Franchise
	 * @param hasAirport of the Franchise
	 * @throws IllegalArgumentException
	 */
	public Franchise(String name, Address address, boolean hasAirport)
	                               throws IllegalArgumentException{	
		
		   if(name == null || name=="") 
			  throw new IllegalArgumentException("Nao e permitido nome nulo ou vazio");
		   this.name = name;
		   
		   if(address == null)
			   throw new IllegalArgumentException("Nao e permitido endereco nulo");
		   this.address = address;
		   
		   this.hasAirport = hasAirport;		   
		   
	}

	public String getName(){
		return this.name;
	}
	
	public void setName(String name)throws Exception{
		if(name == null || name == "")
			throw new Exception("Nao e permitido nome nulo ou vazio");
		this.name = name;
	}
	
	/**
	 * Set the hasAirport data.
	 * @param hasAirport new state
	 */
	public void setHasAirport(boolean hasAirport) {
		this.hasAirport = hasAirport;
	}
	
	public Address getAddress(){
		return this.address;
	}
	
	/**
	 * Set Address of Franchise
	 * @param address address of Franchise
	 * @throws Exception caso o endereco seja nulo
	 */
	public void setAddress(Address address)throws Exception{
		if(address == null) 
			throw new Exception("o endereco nao pode ser nulo");
		this.address = address;
	}
	
	/**
	 * Return if has Airport
	 * @return if has Airport on City
	 */
	public boolean hasAirport(){
		return this.hasAirport;
	}	
	
	@Override
	public boolean equals(Object obj){
		if(!(obj instanceof Franchise))
			return false;
		Franchise other = (Franchise)obj;
		
		return other.getAddress().equals(other.getAddress());
	}
	
	@Override
	public String toString() {
		return String.format("Nome: %s%nEndereço: %n%s%nTemAeroporto: %s%n", name, address, hasAirport);
	}		
	
	public void receivePackage(Package packages){}
}
